# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=dlib
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=19.10
pkgrel=1
pkgdesc="A toolkit for making real world machine learning and data analysis applications in C++ (mingw-w64)"
arch=('any')
url='http://dlib.net/'
license=('Boost')
depends=("${MINGW_PACKAGE_PREFIX}-lapack"
  "${MINGW_PACKAGE_PREFIX}-giflib"
  "${MINGW_PACKAGE_PREFIX}-libpng"
  "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
  "${MINGW_PACKAGE_PREFIX}-openblas"
  "${MINGW_PACKAGE_PREFIX}-lapack"
  "${MINGW_PACKAGE_PREFIX}-fftw"
  "${MINGW_PACKAGE_PREFIX}-sqlite3"
  )

makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/davisking/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('bf416c91d81e5218841965c12a1c0528062869f37d0b713d2dd4c7de11cef8ba')


prepare() {
  cd "$srcdir"/${_realname}-${pkgver}
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -USE_AVX_INSTRUCTIONS=ON \
      -DDLIB_ISO_CPP_ONLY=OFF \
      -DDLIB_IN_PROJECT_BUILD=OFF \
      -DDLIB_USE_CUDA=OFF \
      -DDLIB_JPEG_SUPPORT=ON \
      -DDLIB_PNG_SUPPORT=ON \
      -DDLIB_GIF_SUPPORT=ON \
      -DDLIB_LINK_WITH_SQLITE3=ON \
      -DDLIB_USE_FFTW=ON \
      -DBUILD_SHARED_LIBS=ON \
      ../${_realname}-${pkgver}

  cmake --build . --config Release
}

#check() {
  #cd "${srcdir}"/build-${CARCH}
  #make check
#}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
